Here, you'll learn about cascading style
sheets or CSS in JavaScript or Js concept. CSS in JS is not a specific library, but it's a concept that tries to solve the
problem of styling in React applications. It relies on the implementation
of JavaScript modules. It automates scoping by
generating unique selectors. It promotes explicit traceable and
granular dependencies. It helps with removing dead code. It helps to avoid non deterministic
source order specificity. It encourages the coupling of CSS and
Hypertext Markup Language or HTML. It gives developers an Application
Programming Interface or API to describe state based styles in a better way than
using a bunch of conditional class names. It gives the developer more
expressiveness while encouraging more maintainable patterns than cascading. You can wrap up the component with
styles and use it directly Using some external third party packages like
styled-components, emotion, radium. Now, you'll learn the advantages of
using the styled-components package for styling React components. Automatic critical CSS. Styled- components, keep track of the components that
are rendered on the page and inject their styles fully automatically
combined with code splitting. Which means that the user loads
the least amount of code. No class name bugs. Styled-components generate unique
class names for your styles. Which means you don't have to worry about
duplication, overlapping and misspellings. Easier deletion of CSS. It can be hard to know whether a class
name is used somewhere in your code base. Styled-components make it obvious
as every bit of styling is tied to a specific component. If tooling detects any unused component, the component gets deleted
along with its styles. Simple dynamic styling. Adapting the styling of a component
based on its props or a global theme is simple and intuitive as you don't have
to manage dozens of classes manually. Painless maintenance. You never have to hunt across different
files to find the styling affecting your component. So maintenance is easier no
matter how big your code bases. Automatic vendor prefixing. Write your CSS to the current standard and
let styled-components handle the rest. Here you'll learn about the steps to
install the styled components package in React. Step one, open the terminal of the root
folder of your app and paste npm install save styled-components or
yarn add styled-components and execute it. Which will install the styled
components package in your app. Step two, now to verify
the installation of your package, open the package.json file and check for
styled components under dependency object. Here, you'll learn about CSS in JS styles
using the styled-components package. Styled-components allow you to style any
custom component that you've created. Styled-components utilized tagged template
liberals to style your components. It removes the mapping between
components and styles. You can access props value in
a style-component by passing a function interpolation to
a styled-components template, literal to change the styling
based on the condition of props. Here, you can see an example of a custom
button component that is created using the styled-components package. You can define your own custom
button with custom styling and this can be directly used
as a React component. The image shown is of a styled-component
in which the class name is dynamically created with a unique combination of
characters for each styled-component. As you see in the developer tool,
class name has a unique name in a similar way it follows for
all the styled-components. Here, you'll learn about
a higher order component or HOC. It is an advanced technique used in
React for reusing component logic. And HOC is a pattern that emerges
from React compositional nature and it is not a part of React API. The image shown is of an HOC. In React higher order components
are components that take an origin component as their argument and provide a new component with extensible
logic within higher order component. It is an HOC function that wraps
around a React component or inner component A to provide
access to component A. That is where component B
can be an app component and inter component A can represent data or
state. And HOC comprises component A and component B to get improved or
enhanced components. Now let's learn some of
the cases where an HOC is used. Showing a loader while
a component waits for data. Conditionally rendering components. Managing common user interaction states. Providing components with specific styles. Providing a component with
just any prop that you want. This is an example of an HOC where the HOC
function accepts wrapped component as an argument and returns by
enhancing it with additional props.